local yui_reset = require("zwsapi.yui_reset")
module(..., package.seeall)

actions = {}

actions.css = function(user,dal,page,act,params)
	local app=dal.APP or app
	-- Run the css content through cosmo in order to allow for relative URLS
	local content = cosmo.f(page.content){
		make_url = function(arg)
			return app:make_url(arg.node, arg.action)
		end,
	}
	return content, "text/css"
end

actions.fancy_css = function(user,dal,page,act,params)
	local app=dal.APP or app
	require"colors"
	require"zdc.sandbox"
	local env={
							reset_code = yui_reset.css,
							icon_base_url	 = app.config.ICON_BASE_URL or app.config.NICE_URL,
							string = string,
							table  = table,
							MAIN_COLOR = app.config.MAIN_COLOR,
							BODY_BG_COLOR = app.config.BODY_BG_COLOR,
							colors = colors,
							ipairs = ipairs,
							unpack = unpack,
							config = page.config,
							more_css = app.config.MORE_CSS or "",
						 }
	local data, e = zdc.sandbox.conf_do(page.css_config,env,app.logger)
	if e then 
		error(e.err)
	else
		setmetatable(data,{__index=env})
		return cosmo.fill(page.content, data), "text/css"
	end

end

-- vim:ts=3 ss=3 sw=3 expandtab
